package com.tt.Server;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tt.dao.ConnCustomer;
import com.tt.domain.User;

public class ServletDL extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		   request.setCharacterEncoding("utf-8");
		
		   String username = request.getParameter("username");		
           String password = request.getParameter("password");
          
           ConnCustomer conn = new ConnCustomer();
           User user=null;
           try {
			user=conn.getUserByUsernameAndPwd(username, password);
			System.out.println(user.getName()+""+user.getPassword());
		    } catch (SQLException e) {

			e.printStackTrace();
		    }finally{
           if(user==null){
		    	System.out.println("can not find you push");
		    	response.getWriter().print("can not find");			
		    }else{
		    	System.out.println(username+""+password);
		    	response.sendRedirect("/2.html");
		    }
		    }
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
